﻿using SH.Room.Domain.RoomClass;
using SH.Room.Infrastructure.IRepository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using System.Transactions;
using MySqlConnector;
using DotNetCore.CAP;
using DotNetCore.CAP.MySql;
using EventBusETO.RoomType;
using SH.Common.CommonReturn;
using SH.Room.ErrorCodeEnum;

namespace SH.Room.Infrastructure.Repository
{
    public class RoomTypeRepository : BaseRepository<RoomType>, IRoomTypeRepository
    {
        private readonly ISqlSugarClient _context;
        public RoomTypeRepository(ISqlSugarClient context) : base(DbManger.BizDb)
        {
            _context = DbManger.BizDb;
        }

        /// <summary>
        /// 房型删除
        /// </summary>
        /// <param name="rtid">房型ID</param>
        /// <returns>受影响行数</returns>
        public ApiResult<int> DeleteRoomType(int rtid)
        {
            ApiResult<int> apiResult = new ApiResult<int>();    
           var item=_context.Deleteable<RoomType>().Where(x=>x.Rtid== rtid).ExecuteCommand();
            return apiResult;
        }

        /// <summary>
        /// 修改房型排序
        /// </summary>
        /// <param name="rtid">房型ID</param>
        /// <param name="rsort">排序</param>
        /// <returns>受影响行数</returns>
        public ApiResult<int> GetRoomTypeUpd(int rtid, int rsort)
        {
            ApiResult<int> apiResult= new ApiResult<int>();
            var result = _context.Updateable<RoomType>().SetColumns(x => x.Rsort == rsort).Where(x => x.Rtid == rtid).ExecuteCommand();
            apiResult.Success();
            return apiResult;
        }
    }
}
